package com.primaryAlgorithm;

/**
 * Description:
 * Copyright:   Copyright (c)2019
 * Company:     zefu
 *
 * @author: 张李鑫
 * @version: 1.0
 * Create at:   2021-09-26 01:14:41
 * <p>
 * Modification History:
 * Date         Author      Version     Description
 * ------------------------------------------------------------------
 * 2021-09-26     张李鑫                     1.0         1.0 Version
 */
public class MergeTwoLists {

    public static class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
    }


    public static ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        ListNode listNode = new ListNode(0);
        ListNode p3 = listNode;
        ListNode p1 = l1;
        ListNode p2 = l2;
        while (p1 != null && p2 != null) {
            if (p1.val > p2.val) {
                p3.next = new ListNode(p2.val);
                p2 = p2.next;
                p3 = p3.next;
            } else {
                p3.next = new ListNode(p1.val);
                p1 = p1.next;
                p3 = p3.next;
            }
        }
        while (p1 != null) {
            p3.next = new ListNode(p1.val);
            p3=p3.next;
            p1 = p1.next;
        }
        while (p2 != null) {
            p3.next = new ListNode(p2.val);
            p3=p3.next;
            p2 = p2.next;
        }
        return listNode.next;
    }

    public static void main(String[] args) {
        ListNode listNode1 = new ListNode(-9);
        ListNode listNode2 = new ListNode(3);

        listNode1.next=listNode2;

        ListNode listNode3 = new ListNode(5);
        ListNode listNode = new ListNode(7);
        listNode3.next=listNode;


        ListNode listNode4 = mergeTwoLists(listNode1, listNode3);
        System.out.println(123);
    }


}